{extend name="platform/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style>
.set-style dl:after{
	content:'';
	display:block;
	height:0px;
	clear:both;
}
.set-style dl dt{
	display:block;
	width:20%;
	float:left;
	text-align:right;
}
.set-style dl dd{
	display:block;
	width:80%;
	float:left;
}
.set-style dl dd textarea{
	font-size: 12px;
    color: #777;
    background-color: #FFF;
    vertical-align: top;
    display: inline-block;
    height: 60px;
    padding: 4px;
    border: solid 1px #CCC;
    outline: none;
    width: 400px;
    margin: 0;
}
.textarea-common{
	border-radius: 0 !important;
    resize: none !important;
    width: 250px !important;
    box-sizing: border-box !important;
}
</style>
{/block}
 {block name="main"}
<div class="row padder-v">
	<div class="col-sm-3">
		<!-- 			<a href="PLATFORM_MAIN/Auth/addUser" class="btn btn-sm btn-primary"> -->
		<!-- 			<i class="fa fa-plus"></i> 添加用户 </a> -->
	</div>
	
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="goods_name" class="input-sm form-control" placeholder="请输入商品名称"> 
	</div>
	
	<div class="col-sm-2">
		<select class="input-sm form-control" id="ct_id" >
			<option value="">请选择咨询类型</option>
            {foreach name="ct_list" item="v"}
			<option value="{$v['ct_id']}">{$v['ct_name']}</option>
			{/foreach}
       </select>	
	</div>
	
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="startDate" placeholder="请选择开始日期" class="input-sm form-control" onclick="WdatePicker()">
	</div>
	<div class="col-sm-2 js-shop-block" >
		<input type="text" id="endDate" placeholder="请选择结束日期" class="input-sm form-control" onclick="WdatePicker()">
	</div>

	<div class="col-sm-1">
		<button class="btn btn-sm btn-default" type="button" onclick="LoadingInfo(1)">搜索</button>
	</div>
</div>
<section class="panel panel-default">
	<div class="table-responsive">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col style="width: 2%;">
				<col style="width: 28%;">
				<col style="width: 30%;">
				<col style="width: 30%;">
				<col style="width: 10%;">
			</colgroup>
			<thead>
				<tr>
					<th><input type="checkbox"></th>
					<th colspan="2" >商品</th>
					<th>咨询用户</th>
					<th class="center">咨询时间</th>
					<th class="center">操作</th>
				</tr>
			</thead>
			<tbody id="list">
				
			</tbody>
		</table>
	</div>
	
	<!-- 咨询管理 -->
	<div class="modal fade" id="consult">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">咨询管理</h4>
				</div>
				
				<div class="modal-body">
					<div class="set-style">
						<dl>
							<dt>咨询内容：</dt>
							<dd id="consult_content">
							</dd>
						</dl>
						<dl>
							<dt>回复内容：</dt>
							<dd>
								<textarea id="consult_reply" class="textarea-common" ></textarea>
							</dd>
						</dl>
					</div>
				</div>
				
				<div class="modal-footer">
					<input type="hidden" id="consult_id" >
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-info" onclick="replyConsultAjax()">确定</button>
				</div>
			</div>
		</div>
	</div>	
	
	{include file="platform/page" /}
</section>
{/block} 
{block name="script"}
<link rel="stylesheet" type="text/css" href="__ROOT__/public/admin/css/plugin/jquery.searchableSelect.css">
<script src="__ROOT__/public/admin/js/plugin/jquery.searchableSelect.js"></script>
<script src="__STATIC__/js/BootstrapMenu.min.js"></script>

<script type="text/javascript">

	$(function(){
		LoadingInfo(1);
	});


	//查询用户列表
	function LoadingInfo(pageIndex) {
		
		var shop_id = $("#shop_id").val();
		var ct_id = $("#ct_id").val();
		var type = $("#type").val();
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var goods_name =$("#search_text").val();
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/saleservice/consultlist')}",
			async : true,
			data : {
				"shop_id" : shop_id,
				"page_index" : pageIndex, 
				"ct_id" : ct_id, 
				'type' : type, 
				"start_date":start_date,
				"end_date":end_date,
				"goods_name" : $("#goods_name").val()
			},
			success : function(data) {
				//console.log(data);return;
				var html = '';
				$("#total_count_num").text(data["total_count"]);
				$("#page_count_num").text(data["page_count"]);
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				
				if (data["data"].length > 0) {
					
					for (var i = 0; i < data["data"].length; i++) {
						
						html += '<tr class="tr-title"><td class="td-'+ data["data"][i]["consult_id"]+'" align="center" rowspan="2"><i class="checkbox-common"><input value="'
							+ data["data"][i]["consult_id"]
							+ '" name="sub" data-state="'+data["data"][i]["state"]+'" type="checkbox" ></i></td>';
						html += '<td colspan="2"  align="left" style="border-left:1px solid #e5e5e5;">';
						html += '商品名称：<a href="'+__URL('SHOP_MAIN/goods/goodsinfo?goodsid='+ data["data"][i]["goods_id"])+'" target="_blank">'+ data["data"][i]["goods_name"] + '</a><br/>'
						html += '店铺名称：<a>'+ data["data"][i]["shop_name"] +'</a>';
						html += '</td>';
						if(data["data"][i]["uid"] == 0){
							html += '<td align="left"><span class="pro-code">游客</span></td>';
						}else{
							html += '<td align="left"><span class="pro-code">'+data["data"][i]["member_name"]+'</span></td>';
						}
						html += '<td align="center" style="border-right:1px solid #e5e5e5;">'+timeStampTurnTime(data["data"][i]["consult_addtime"]);
						html += '</div></td>';
						html += '<td align="center" rowspan="2">';
						if(data["data"][i]["consult_reply"] != ''){
							html += '<a href="javascript:;" data-placement="bottom" data-original-title="编辑" onclick="replyConsult('+ data["data"][i]["consult_id"]+ ',this)">编辑</a>&nbsp;';
						}else{
							html += '<a href="javascript:;" data-placement="bottom" data-original-title="回复" onclick="replyConsult(' + data["data"][i]["consult_id"] + ',this)">回复</a>&nbsp;';
						}
						
						html += '<a href="javascript:void(0)" data-placement="bottom" onclick="deleteConsult(' + data["data"][i]["consult_id"] + ')" data-original-title="删除">删除</a></td>';
						html += '</tr>';
						
						html += '<tr>';
						html += '<td colspan="4">';
						html += '<p><span>咨询内容:</span> <span class="consult_content">'+ data["data"][i]["consult_content"]+'</span></p>';
						if(data["data"][i]["consult_reply"] != ''){
							html += '<p><span>回复内容:</span> <span class="consult_reply">'+ data["data"][i]["consult_reply"]+'</span></p>';
						}
						html += '</td>';
						
						html += '</tr>';
						
					}
				} else {
					html = '<tr align="center"><td colspan="6" style="text-align: center;">暂无符合条件的数据记录</td></tr>';
					
				}
				$("#list").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
				img_lazyload();
			}
		});
	}
	
	
	$("#search_text").keypress(function(e){
		if(e.keyCode == 13){
			LoadingInfo(1);
		}
	});
	
	//隐藏商品分组
	function hideEditGroup(){
		$("#editGroup").popover("hide");
	}

	function hideSetRecommend(){
		$("#setRecommend").popover("hide");
	}
	
	function batchDelete() {
		var consult_id= new Array();
		$("#productTbody input[type='checkbox']:checked").each(function() {
			if (!isNaN($(this).val())) {
				consult_id.push($(this).val());
			}
		});
		if(consult_id.length ==0){
			$( "#dialog" ).dialog({
				buttons: {
					"确定,#0059d6,#fff": function() {
						$(this).dialog('close');
					}
				},
				contentText:"请选择需要操作的记录",
				title:"消息提醒",
			});
			return false;
		}
		deleteConsult(consult_id);
	}

	// 删除
	function deleteConsult(consult_id){
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$(this).dialog('close');
					$.ajax({
						type : "post",
						url : "{:__URL('PLATFORM_MAIN/saleservice/deleteconsult')}",
						data : { "consult_id" : consult_id.toString() },
						dataType : "json",
						success : function(data) {
							if(data['code'] > 0){
								LoadingInfo($("#pageNumber .active").html());
								showMessage('success', data['message']);
							}else{
								showMessage('error', data['message']);
							}
						}
					});
				},
				"取消,#f5f5f5,#666" : function(){
					$(this).dialog('close');
				}
			},
			contentText:"你确定删除吗？",
			title:"消息提醒"
		});
	}

	//全选
	function CheckAll(event){
		var checked = event.checked;
		if(checked) $("#productTbody input[type = 'checkbox']").prop("checked",checked).parent().addClass("selected");
		else $("#productTbody input[type = 'checkbox']").prop("checked",checked).parent().removeClass("selected");
	}

	//回复 弹出框
	function replyConsult(consult_id, event){
		var consult_content = $(event).parents('tr').next().find('.consult_content').html();
		var consult_reply = $(event).parents('tr').find('.consult_reply').html();
		if(consult_reply == undefined){
			consult_reply = '';
		}
		$("#consult_reply").val(consult_reply);
		$("#consult").modal('show');
		$("#consult_id").val(consult_id);
		$("#consult_content").html(consult_content);
	}

	// 回复提交
	function replyConsultAjax(){
		var consult_id = $("#consult_id").val();
		var consult_reply = $("#consult_reply").val();
		
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/saleservice/replyconsultAjax')}",
			data : { "consult_id" : consult_id, "consult_reply" : consult_reply },
			success : function(data) {
				if(data['code'] > 0){
					LoadingInfo($("#pageNumber .active").html());
					showMessage('success', data['message']);
				}else{
					showMessage('error', data['message']);
				}
				$("#consult").modal('hide');
			}
		});
	}
</script>
{/block}
